﻿using System.Collections.Generic;
using System.Linq;
using Melee.DataContract.Views;
using Melee.Infrastructure.Configuration;
using Melee.Models.Entity;

namespace Melee.DataContract.Extension
{
    public static class CityExtensionMethod
    {
        public static IEnumerable<CityView> ConvertToCityViewOfMap(this IEnumerable<City> cities)
        {
            return cities.Select(city => new CityView
            {
                Durable = city.MaxDurable,
                X = city.StartingPoint.X * ApplicationSettingsFactory.ApplicationSettings.PointLength,
                Y = city.StartingPoint.Y * ApplicationSettingsFactory.ApplicationSettings.PointLength,
                Width = city.Level.Width * ApplicationSettingsFactory.ApplicationSettings.PointLength,
                Height = city.Level.Height * ApplicationSettingsFactory.ApplicationSettings.PointLength,
                Id = city.Id.ToString(),
                Img = string.Format("images\\city\\{0}", city.Level.Thumbnail),
                Name = city.Name,
                Troops = city.MaxTroops
            });
        }

        public static PlayerCityView ConvertToPlayerCityView(this City city)
        {
            return new PlayerCityView
            {
                Id = city.Id.ToString(),
                Durable = city.Durable,
                Troops = city.Troops,
                Atk = city.Atk
            };
        }
    }
}
